package cn.yeamin.spring.boot.dao;

import cn.yeamin.spring.boot.domain.Girl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;


@CacheConfig(cacheNames = "girls")
public interface GirlRepository extends JpaRepository<Girl, Integer> {

    @Cacheable(key = "#p0.toString()")
    Girl findByName(String name);

    @Cacheable(key = "#p0.toString()")
    Girl findById(Integer id);


    @CachePut(key = "#p0.id.toString()")
    Girl save(Girl girl);


    @CacheEvict(allEntries = true)
    void delete(Integer id);



    List<Girl> findAll();
}
